package org.dromara.system.api.services;

import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.dromara.common.core.domain.R;
import org.dromara.common.core.utils.AssertUtils;
import org.dromara.system.api.feign.SystemPermissionClient;
import org.springframework.stereotype.Service;

import java.util.Set;

/**
 * @author: zhou shuai
 * @date: 2025/7/12 16:12
 * @version: v1
 */
@Slf4j
@Service("sysPermissionApiService")
@RequiredArgsConstructor
public class SysPermissionApiService {

    private final SystemPermissionClient systemPermissionClient;

    /**
     * 根据用户ID获取角色数据权限
     *
     * @param userId 用户ID
     */
    public Set<String> getRolePermission(Long userId) {
        R<Set<String>> rolePermissionResult = systemPermissionClient.getRolePermission(userId);
        AssertUtils.assertTrue(R.isSuccess(rolePermissionResult), "根据用户ID获取角色数据权限失败");
        return rolePermissionResult.getData();
    }

    /**
     * 根据用户ID获取菜单数据权限
     *
     * @param userId 用户ID
     */
    public Set<String> getMenuPermission(Long userId) {
        R<Set<String>> menuPermissionResult = systemPermissionClient.getMenuPermission(userId);
        AssertUtils.assertTrue(R.isSuccess(menuPermissionResult), "根据用户ID获取菜单数据权限失败");
        return menuPermissionResult.getData();
    }

}
